<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新增职位 - HRM系统</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <link rel="stylesheet" th:href="@{/css/position-add.css}">
</head>
<body>
<div class="dashboard">
    <header class="header">
        <div class="logo">HRM系统</div>
        <div class="user-info">
            <span th:text="${currentUser.realName}"></span>
            <span class="role-badge" th:text="${currentUser.roleId.roleName}"></span>
            <a href="/logout" class="logout-btn">退出</a>
        </div>
    </header>
    <main class="position-add-container">
        <div class="back-container">
            <a th:href="@{/position}" class="btn btn-back">← 返回职位列表</a>
            <a th:href="@{/home}" class="btn btn-back">← 返回首页</a>
        </div>

        <div class="module-header">
            <h1 class="module-title">新增职位</h1>
        </div>

        <div class="position-form-card">
            <form id="addPositionForm" th:action="@{/position/add}" method="post" th:object="${positionAddDTO}">
                <div class="form-group">
                    <label for="positionName">职位名称</label>
                    <input type="text" id="positionName" th:field="*{positionName}" required
                           placeholder="请输入职位名称" maxlength="50">
                    <div class="error-message" th:if="${#fields.hasErrors('positionName')}"
                         th:errors="*{positionName}"></div>
                </div>

                <div class="form-group">
                    <label for="positionCode">职位代码</label>
                    <input type="text" id="positionCode" th:field="*{positionCode}" required
                           placeholder="请输入职位代码" maxlength="20">
                    <div class="error-message" th:if="${#fields.hasErrors('positionCode')}"
                         th:errors="*{positionCode}"></div>
                </div>

                <div class="form-group">
                    <label for="departmentId">所属部门</label>
                    <select id="departmentId" th:field="*{departmentId}" required>
                        <option value="">-- 请选择部门 --</option>
                        <option th:each="dept : ${departments}"
                                th:value="${dept.departmentID}"
                                th:text="${dept.departmentName}"></option>
                    </select>
                    <div class="error-message" th:if="${#fields.hasErrors('departmentId')}"
                         th:errors="*{departmentId}"></div>
                </div>

                <div class="form-group">
                    <label for="positionRoleId">职位角色</label>
                    <select id="positionRoleId" th:field="*{positionRoleId}" required>
                        <option value="">-- 请选择角色 --</option>
                        <option th:each="role : ${roles}"
                                th:value="${role.roleId}"
                                th:text="${role.roleName}"></option>
                    </select>
                    <div class="error-message" th:if="${#fields.hasErrors('positionRoleId')}"
                         th:errors="*{positionRoleId}"></div>
                </div>

                <div class="form-group">
                    <label for="maxHeadCount">最大人数</label>
                    <input type="number" id="maxHeadCount" th:field="*{maxHeadCount}"
                           placeholder="请输入最大人数" min="1">
                    <div class="error-message" th:if="${#fields.hasErrors('maxHeadCount')}"
                         th:errors="*{maxHeadCount}"></div>
                </div>

                <div class="form-group">
                    <label for="baseSalary">基本工资</label>
                    <input type="number" id="baseSalary" th:field="*{baseSalary}" step="0.01"
                           placeholder="请输入基本工资" min="0">
                    <div class="error-message" th:if="${#fields.hasErrors('baseSalary')}"
                         th:errors="*{baseSalary}"></div>
                </div>

                <div class="form-group">
                    <label for="allowance">津贴</label>
                    <input type="number" id="allowance" th:field="*{allowance}" step="0.01"
                           placeholder="请输入津贴" min="0">
                    <div class="error-message" th:if="${#fields.hasErrors('allowance')}"
                         th:errors="*{allowance}"></div>
                </div>

                <div class="form-group">
                    <label for="annualLeaveDays">年假天数</label>
                    <input type="number" id="annualLeaveDays" th:field="*{annualLeaveDays}" step="0.5"
                           placeholder="请输入年假天数" min="0">
                    <div class="error-message" th:if="${#fields.hasErrors('annualLeaveDays')}"
                         th:errors="*{annualLeaveDays}"></div>
                </div>

                <div class="form-actions">
                    <button type="submit" class="btn btn-primary">保存</button>
                    <button type="button" class="btn btn-secondary" onclick="window.history.back()">取消</button>
                </div>
            </form>
        </div>
    </main>
</div>
<script th:src="@{/js/position-add.js}"></script>
</body>
</html>